< previous page page_442 next page >

Page 442
Using the Font Object
If you have used a word processor program, then you are already familiar with fonts. At designtime, you assign fonts to controls and forms by using the Properties window. If you set the font of a form, any controls subsequently drawn on the form will use the same font.
You may remember from earlier chapters that the Font property of an object is actually an object that has its own properties. The following Font object properties can be used to control the appearance of fonts in your program:
Name. String identifier for one of the fonts installed on your systemfor example, "Arial" or "Times New Roman".
Bold. True/False property that controls the boldface attribute of the font. The bold letters appear darker and heavier than nonbold characters.
Italic. True/False property that determines whether letters are italicized.
Underline. True/False property that controls whether the text is displayed with a thin line under each character.
Size. Controls the point size of a font. One point is 1/72 of an inch; therefore, capital letters in a 72-point font are about one inch high.
Strikethrough. True/False property that controls whether a thin line is drawn through the middle of the text.
Weight. Controls the width of the line used to draw text. The two settings for Weight are 400 and 700. These settings correspond to normal and bold text, respectively.
Charset. Controls the character set (standard, extended DOS, Japanese). This property is explained in more detail in the Help file.
As you may have already noticed, before you can set a particular font, you have to know its name. Not all systems have the same fonts installed. The Screen and Printer objects have a Fonts collection that lists the available fonts. You can write a quick program to list the available fonts on your system. Start a new project now and place the following code in the form's Click event. Clicking the form causes the name of each installed font to be printed on the form:
Dim nCount As Integer
Me.AutoRedraw = True
For nCount = 0 To Screen.FontCount - 1
  Me.Font.Name = Screen.Fonts(nCount)
  Me.Print Screen.Fonts(nCount)
Next nCount
Also, note that most fonts contain extra characters, beyond those that you can type on the keyboard. For example, the MS Sans Serif font contains special characters for fractions and accented letters. These characters can be displayed by using the Chr$ function. The following code displays all 256 available characters (many of which are unprintable) on the form:
Dim i As Integer

For i = 0 To 255
    Me.Print Chr$(i); " ";
    If Me.CurrentX >= Me.Width Then Me.Print
Next i

 
< previous page page_442 next page >